***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\naep\1996ScienceY17.dta", clear
append using "${path}\data\naep\2000ScienceY17.dta", force
append using "${path}\data\naep\2005ScienceY17.dta", force
append using "${path}\data\naep\2009ScienceY17.dta", force

***align waves

foreach v of var * {
	rename `v' `=lower("`v'")'
}

numlabel, add

recode year (27=1996) (31=2000) (36=2005) (40=2009) (46=2015)

gen state=.
replace state=fips if year==1996
replace state=fips00 if year==2000
encode repsubg if year==2005, gen(state2005) 
recode state2005 (1=.) (2=1) (3=5) (4=4) (5=.) (6=6) (7=8) (8=9) (9=11) (10=10) (11=.) (12=12) (13=13) (14=15) (15=19) (16=16) (17=17) (18=18) (19=20) (20=21) (21=22) (22=25) (23=24) (24=23) (25=26) (26=27) (27=29) (28=28) (29=30) (30=37) (31=38) (32=31) (33=33) (34=34) (35=35) (36=32) (37=36) (38=39) (39=40) (40=.) (41=41) (42=42) (43=.) (44=44) (45=45) (46=46) (47=47) (48=48) (49=49) (50=51) (51=50) (52=53) (53=55) (54=54)
replace state=state2005 if year==2005
replace state=fipsloc if year==2009

***prepare outcomes

gen evolution_1996_1=k052001k
recode evolution_1996_1 (0=0) (1=1) (2=0) (3=0) (4=0)(8=0) (9=0)
label define evolution_1996_1 1 "correct" 0 "incorrect"
label values evolution_1996_1 evolution_1996_1

gen evolution_1996_2=k052101k 
recode evolution_1996_2 (0=0) (1=1) (2=0) (3=0) (4=0)(8=0) (9=0)
label define evolution_1996_2 1 "correct" 0 "incorrect"
label values evolution_1996_2 evolution_1996_2

gen evolution_2000_tree=k052001 
recode evolution_2000_tree (0=0) (1=0) (2=1) (3=0) (4=0)(8=0) (9=0)
label define evolution_2000_tree 1 "correct" 0 "incorrect"
label values evolution_2000_tree evolution_2000_tree

gen evolution_2000_selection=k052101 
recode evolution_2000_selection (0=0) (1=0) (2=0) (3=0) (4=1) (8=0) (9=0)
label define evolution_2000_selection 1 "correct" 0 "incorrect"
label values evolution_2000_selection evolution_2000_selection

gen evolution_2000_plants=k100501  
recode evolution_2000_plants (0=0) (1=0) (2=0) (3=0) (4=1) (8=0) (9=0)
label define evolution_2000_plants 1 "correct" 0 "incorrect"
label values evolution_2000_plants evolution_2000_plants

gen evolution_2000_relationships=k090301  
recode evolution_2000_relationships (1=0) (2=0) (3=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define evolution_2000_relationships 1 "correct" 0 "incorrect"
label values evolution_2000_relationships evolution_2000_relationships

gen evolution_2005_selection=k075801  
recode evolution_2005_selection (1=0) (2=0) (3=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define evolution_2005_selection 1 "correct" 0 "incorrect"
label values evolution_2005_selection evolution_2005_selection

gen evolution_2009_tree=k131102 
recode evolution_2009_tree (1=0) (2=0) (3=0) (4=1) (8=0) (9=0)
label define evolution_2009_tree 1 "correct" 0 "incorrect"
label values evolution_2009_tree evolution_2009_tree

gen evolution_2009_fibers=k138601 
recode evolution_2009_fibers (1=0) (2=0) (3=1) (4=0) (8=0) (9=0)
label define evolution_2009_fibers 1 "correct" 0 "incorrect"
label values evolution_2009_fibers evolution_2009_fibers

gen evolution_2009_bacteria=k132701 
recode evolution_2009_bacteria (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (8=0) (9=0)
label define evolution_2009_bacteria 1 "correct" 0 "incorrect"
label values evolution_2009_bacteria evolution_2009_bacteria

gen evolution_2009_genetics=k143101 
recode evolution_2009_genetics (1=0) (2=0) (3=0) (4=1) (6=0) (8=0) (9=0)
label define evolution_2009_genetics 1 "correct" 0 "incorrect"
label values evolution_2009_genetics evolution_2009_genetics

gen evolution_2009_selection=k136401 
recode evolution_2009_selection (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (8=0) (9=0)
label define evolution_2009_selection 1 "correct" 0 "incorrect"
label values evolution_2009_selection evolution_2009_selection

gen v2_evolution_1996_1=k052001k 
recode v2_evolution_1996_1 (0=0) (1=1) (2=0) (3=0) (4=0) (8=.) (9=.)
label define v2_evolution_1996_1 1 "correct" 0 "incorrect"
label values v2_evolution_1996_1 v2_evolution_1996_1

gen v2_evolution_1996_2=k052101k 
recode v2_evolution_1996_2 (0=0) (1=1) (2=0) (3=0) (4=0)(8=.) (9=.)
label define v2_evolution_1996_2 1 "correct" 0 "incorrect"
label values v2_evolution_1996_2 v2_evolution_1996_2

gen v2_evolution_2000_tree=k052001 
recode v2_evolution_2000_tree (0=0) (1=0) (2=1) (3=0) (4=0)(8=.) (9=.)
label define v2_evolution_2000_tree 1 "correct" 0 "incorrect"
label values v2_evolution_2000_tree v2_evolution_2000_tree

gen v2_evolution_2000_selection=k052101 
recode v2_evolution_2000_selection (0=0) (1=0) (2=0) (3=0) (4=1) (8=.) (9=.)
label define v2_evolution_2000_selection 1 "correct" 0 "incorrect"
label values v2_evolution_2000_selection v2_evolution_2000_selection

gen v2_evolution_2000_plants=k100501  
recode v2_evolution_2000_plants (0=0) (1=0) (2=0) (3=0) (4=1) (8=.) (9=.)
label define v2_evolution_2000_plants 1 "correct" 0 "incorrect"
label values v2_evolution_2000_plants v2_evolution_2000_plants

gen v2_evolution_2000_relationships=k090301  
recode v2_evolution_2000_relationships (1=0) (2=0) (3=1) (5=.) (6=.) (7=.) (8=.) (9=.)
label define v2_evolution_2000_relationships 1 "correct" 0 "incorrect"
label values v2_evolution_2000_relationships v2_evolution_2000_relationships

gen v2_evolution_2005_selection=k075801  
recode v2_evolution_2005_selection (1=0) (2=0) (3=1) (5=.) (6=.) (7=.) (8=.) (9=.)
label define v2_evolution_2005_selection 1 "correct" 0 "incorrect"
label values v2_evolution_2005_selection v2_evolution_2005_selection

gen v2_evolution_2009_tree=k131102 
recode v2_evolution_2009_tree (1=0) (2=0) (3=0) (4=1) (8=.) (9=.)
label define v2_evolution_2009_tree 1 "correct" 0 "incorrect"
label values v2_evolution_2009_tree v2_evolution_2009_tree

gen v2_evolution_2009_fibers=k138601 
recode v2_evolution_2009_fibers (1=0) (2=0) (3=1) (4=0) (8=.) (9=.)
label define v2_evolution_2009_fibers 1 "correct" 0 "incorrect"
label values v2_evolution_2009_fibers v2_evolution_2009_fibers

gen v2_evolution_2009_bacteria=k132701 
recode v2_evolution_2009_bacteria (1=0) (2=0) (3=1) (4=0) (5=.) (6=.) (8=.) (9=.)
label define v2_evolution_2009_bacteria 1 "correct" 0 "incorrect"
label values v2_evolution_2009_bacteria v2_evolution_2009_bacteria

gen v2_evolution_2009_genetics=k143101 
recode v2_evolution_2009_genetics (1=0) (2=0) (3=0) (4=1) (6=.) (8=.) (9=.)
label define v2_evolution_2009_genetics 1 "correct" 0 "incorrect"
label values v2_evolution_2009_genetics v2_evolution_2009_genetics

gen v2_evolution_2009_selection=k136401 
recode v2_evolution_2009_selection (1=0) (2=0) (3=1) (4=0) (5=.) (6=.) (8=.) (9=.)
label define v2_evolution_2009_selection 1 "correct" 0 "incorrect"
label values v2_evolution_2009_selection v2_evolution_2009_selection

gen matter_acceleration=k047101l  
recode matter_acceleration (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define matter_acceleration 1 "correct" 0 "incorrect"
label values matter_acceleration matter_acceleration

gen matter_mass=k050802j  
recode matter_mass (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (8=0) (9=0)
label define matter_mass 1 "correct" 0 "incorrect"
label values matter_mass matter_mass
 
gen matter_cycles=k105501  
recode matter_cycles (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define matter_cycles 1 "correct" 0 "incorrect"
label values matter_cycles matter_cycles

gen matter_phases=k072601 
recode matter_phases (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define matter_phases 1 "correct" 0 "incorrect"
label values matter_phases matter_phases

gen matter_conservation=k125802 
recode matter_conservation (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define matter_conservation 1 "correct" 0 "incorrect"
label values matter_conservation matter_conservation

gen mass_pendulum=k049707  
recode mass_pendulum (0=0) (1=0) (2=0) (3=0) (4=0) (5=1) (55=0) (66=0) (77=0) (99=0)
label define mass_pendulum 1 "correct" 0 "incorrect"
label values mass_pendulum mass_pendulum

gen mass_force=k047101 
recode mass_force (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define mass_force 1 "correct" 0 "incorrect"
label values mass_force mass_force

gen mass_volume=k074301 
recode mass_volume (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define mass_volume 1 "correct" 0 "incorrect"
label values mass_volume mass_volume

gen mass_gravity=k127001 
recode mass_gravity (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define mass_gravity 1 "correct" 0 "incorrect"
label values mass_gravity mass_gravity

gen energy_fan=k046801l 
recode energy_fan (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_fan 1 "correct" 0 "incorrect"
label values energy_fan energy_fan

gen energy_nuclear=k051401k 
recode energy_nuclear (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_nuclear 1 "correct" 0 "incorrect"
label values energy_nuclear energy_nuclear

gen energy_source=k105401 
recode energy_source (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_source 1 "correct" 0 "incorrect"
label values energy_source energy_source

gen energy_release=k051401 
recode energy_release (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_release 1 "correct" 0 "incorrect"
label values energy_release energy_release

gen energy_conversion=k046801 
recode energy_conversion (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_conversion 1 "correct" 0 "incorrect"
label values energy_conversion energy_conversion

gen energy_transformation=k096501 
recode energy_transformation (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_transformation 1 "correct" 0 "incorrect"
label values energy_transformation energy_transformation

gen energy_plant=k073001 
recode energy_plant (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_plant 1 "correct" 0 "incorrect"
label values energy_plant energy_plant

gen energy_transfer=k157401 
recode energy_transfer (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_transfer 1 "correct" 0 "incorrect"
label values energy_transfer energy_transfer

gen energy_forces=k128403 
recode energy_forces (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_forces 1 "correct" 0 "incorrect"
label values energy_forces energy_forces

gen energy_storage=k134801 
recode energy_storage (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_storage 1 "correct" 0 "incorrect"
label values energy_storage energy_storage

gen energy_peanut=k131001 
recode energy_peanut (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_peanut 1 "correct" 0 "incorrect"
label values energy_peanut energy_peanut

gen energy_peanut2=k131002 
recode energy_peanut2 (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_peanut2 1 "correct" 0 "incorrect"
label values energy_peanut2 energy_peanut2

gen energy_kinetic=k136101 
recode energy_kinetic (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_kinetic 1 "correct" 0 "incorrect"
label values energy_kinetic energy_kinetic

gen energy_trampoline=k140201 
recode energy_trampoline (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_trampoline 1 "correct" 0 "incorrect"
label values energy_trampoline energy_trampoline

gen energy_potential=k140202 
recode energy_potential (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_potential 1 "correct" 0 "incorrect"
label values energy_potential energy_potential

gen energy_water=k137701 
recode energy_water (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_water 1 "correct" 0 "incorrect"
label values energy_water energy_water

gen energy_change=k144201 
recode energy_change (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_change 1 "correct" 0 "incorrect"
label values energy_change energy_change

gen energy_levels=k144202 
recode energy_levels (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_levels 1 "correct" 0 "incorrect"
label values energy_levels energy_levels

gen energy_decrease=k129001 
recode energy_decrease (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_decrease 1 "correct" 0 "incorrect"
label values energy_decrease energy_decrease

gen energy_molecules=k158901 
recode energy_molecules (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define energy_molecules 1 "correct" 0 "incorrect"
label values energy_molecules energy_molecules

gen motion_graph=k074501 
recode motion_graph (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_graph 1 "correct" 0 "incorrect"
label values motion_graph motion_graph

gen motion_ice=k143001 
recode motion_ice (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_ice 1 "correct" 0 "incorrect"
label values motion_ice motion_ice

gen motion_object=k157501 
recode motion_object (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_object 1 "correct" 0 "incorrect"
label values motion_object motion_object

gen motion_molecule=k128402 
recode motion_molecule (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_molecule 1 "correct" 0 "incorrect"
label values motion_molecule motion_molecule

gen motion_solid=k143601 
recode motion_solid (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_solid 1 "correct" 0 "incorrect"
label values motion_solid motion_solid

gen motion_time=k158201 
recode motion_time (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_time 1 "correct" 0 "incorrect"
label values motion_time motion_time

gen motion_car=k142801 
recode motion_car (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_car 1 "correct" 0 "incorrect"
label values motion_car motion_car

gen motion_sled=k128201 
recode motion_sled (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_sled 1 "correct" 0 "incorrect"
label values motion_sled motion_sled

gen motion_second=k141601 
recode motion_second (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_second 1 "correct" 0 "incorrect"
label values motion_second motion_second

gen motion_interval=k141602 
recode motion_interval (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define motion_interval 1 "correct" 0 "incorrect"
label values motion_interval motion_interval

gen reproduction_diff=k051301k 
recode reproduction_diff (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_diff 1 "correct" 0 "incorrect"
label values reproduction_diff reproduction_diff

gen reproduction_plants=k100601 
recode reproduction_plants (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_plants 1 "correct" 0 "incorrect"
label values reproduction_plants reproduction_plants

gen reproduction_general=k092701 
recode reproduction_general (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_general 1 "correct" 0 "incorrect"
label values reproduction_general reproduction_general

gen reproduction_asexual=k051301 
recode reproduction_asexual (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_asexual 1 "correct" 0 "incorrect"
label values reproduction_asexual reproduction_asexual

gen reproduction_sexual=k129401 
recode reproduction_sexual (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_sexual 1 "correct" 0 "incorrect"
label values reproduction_sexual reproduction_sexual

gen reproduction_advantage=k142001 
recode reproduction_advantage (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_advantage 1 "correct" 0 "incorrect"
label values reproduction_advantage reproduction_advantage

gen reproduction_engineering=k075401 
recode reproduction_engineering (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_engineering 1 "correct" 0 "incorrect"
label values reproduction_engineering reproduction_engineering

gen reproduction_disorders=k075701 
recode reproduction_disorders (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_disorders 1 "correct" 0 "incorrect"
label values reproduction_disorders reproduction_disorders

gen reproduction_mutations=k126501 
recode reproduction_mutations (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_mutations 1 "correct" 0 "incorrect"
label values reproduction_mutations reproduction_mutations

gen reproduction_relatedness=k129602 
recode reproduction_relatedness (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_relatedness 1 "correct" 0 "incorrect"
label values reproduction_relatedness reproduction_relatedness

gen reproduction_parents=k132302 
recode reproduction_parents (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_parents 1 "correct" 0 "incorrect"
label values reproduction_parents reproduction_parents

gen reproduction_offspring=k132303 
recode reproduction_offspring (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_offspring 1 "correct" 0 "incorrect"
label values reproduction_offspring reproduction_offspring

gen reproduction_chromosomes=k132304 
recode reproduction_chromosomes (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_chromosomes 1 "correct" 0 "incorrect"
label values reproduction_chromosomes reproduction_chromosomes

gen reproduction_data=k142701 
recode reproduction_data (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_data 1 "correct" 0 "incorrect"
label values reproduction_data reproduction_data

gen reproduction_genetics=k142703 
recode reproduction_genetics (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_genetics 1 "correct" 0 "incorrect"
label values reproduction_genetics reproduction_genetics

gen reproduction_grain=k127701 
recode reproduction_grain (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_grain 1 "correct" 0 "incorrect"
label values reproduction_grain reproduction_grain

gen reproduction_definition=k054001 
recode reproduction_definition (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_definition 1 "correct" 0 "incorrect"
label values reproduction_definition reproduction_definition

gen reproduction_effect=k054002 
recode reproduction_effect (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_effect 1 "correct" 0 "incorrect"
label values reproduction_effect reproduction_effect

gen  reproduction_hemoglobin=k054003 
recode reproduction_hemoglobin (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_hemoglobin 1 "correct" 0 "incorrect"
label values reproduction_hemoglobin reproduction_hemoglobin

gen reproduction_cell=k054004 
recode reproduction_cell (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_cell 1 "correct" 0 "incorrect"
label values reproduction_cell reproduction_cell

gen reproduction_enzymes=k075301 
recode reproduction_enzymes (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_enzymes 1 "correct" 0 "incorrect"
label values reproduction_enzymes reproduction_enzymes

gen reproduction_regulation=k075501 
recode reproduction_regulation (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_regulation 1 "correct" 0 "incorrect"
label values reproduction_regulation reproduction_regulation

gen reproduction_mutations2=k142704 
recode reproduction_mutations2 (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define reproduction_mutations2 1 "correct" 0 "incorrect"
label values reproduction_mutations2 reproduction_mutations2
 
gen tectonics_composition=k102301 
recode tectonics_composition (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_composition 1 "correct" 0 "incorrect"
label values tectonics_composition tectonics_composition

gen tectonics_layers=k102101 
recode tectonics_layers (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_layers 1 "correct" 0 "incorrect"
label values tectonics_layers tectonics_layers

gen tectonics_comparison=k102001 
recode tectonics_comparison (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_comparison 1 "correct" 0 "incorrect"
label values tectonics_comparison tectonics_comparison

gen tectonics_plate=k097601 
recode tectonics_plate (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_plate 1 "correct" 0 "incorrect"
label values tectonics_plate tectonics_plate

gen tectonics_volcano=k097801 
recode tectonics_volcano (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_volcano 1 "correct" 0 "incorrect"
label values tectonics_volcano tectonics_volcano

gen tectonics_movement=k097701 
recode tectonics_movement (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_movement 1 "correct" 0 "incorrect"
label values tectonics_movement tectonics_movement

gen tectonics_mountains=k098501 
recode tectonics_mountains (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_mountains 1 "correct" 0 "incorrect"
label values tectonics_mountains tectonics_mountains

gen tectonics_properties=k101301 
recode tectonics_properties (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_properties 1 "correct" 0 "incorrect"
label values tectonics_properties tectonics_properties

gen tectonics_circulation=k101401 
recode tectonics_circulation (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_circulation 1 "correct" 0 "incorrect"
label values tectonics_circulation tectonics_circulation

gen tectonics_eruptions=k101501 
recode tectonics_eruptions (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_eruptions 1 "correct" 0 "incorrect"
label values tectonics_eruptions tectonics_eruptions

gen tectonics_earthquakes=k101601 
recode tectonics_earthquakes (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_earthquakes 1 "correct" 0 "incorrect"
label values tectonics_earthquakes tectonics_earthquakes

gen tectonics_sea=k100901 
recode tectonics_sea (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_sea 1 "correct" 0 "incorrect"
label values tectonics_sea tectonics_sea

gen tectonics_land=k101001 
recode tectonics_land (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_land 1 "correct" 0 "incorrect"
label values tectonics_land tectonics_land

gen tectonics_model=k097901 
recode tectonics_model (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_model 1 "correct" 0 "incorrect"
label values tectonics_model tectonics_model

gen tectonics_theory=k135001 
recode tectonics_theory (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_theory 1 "correct" 0 "incorrect"
label values tectonics_theory tectonics_theory

gen tectonics_earthquakes2=k059801 
recode tectonics_earthquakes2 (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define tectonics_earthquakes2 1 "correct" 0 "incorrect"
label values tectonics_earthquakes2 tectonics_earthquakes2

gen earth_atmosphere=k047601l 
recode earth_atmosphere (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_atmosphere 1 "correct" 0 "incorrect"
label values earth_atmosphere earth_atmosphere

gen earth_surface=k144601 
recode earth_surface (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_surface 1 "correct" 0 "incorrect"
label values earth_surface earth_surface

gen earth_age=k129501 
recode earth_age (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_age 1 "correct" 0 "incorrect"
label values earth_age earth_age

gen earth_heat=k139702 
recode earth_heat (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_heat 1 "correct" 0 "incorrect"
label values earth_heat earth_heat

gen earth_age2=k126701 
recode earth_age2 (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_age2 1 "correct" 0 "incorrect"
label values earth_age2 earth_age2

gen earth_heat2=k132101 
recode earth_heat2 (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_heat2 1 "correct" 0 "incorrect"
label values earth_heat2 earth_heat2

gen earth_oxygen=k143201 
recode earth_oxygen (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_oxygen 1 "correct" 0 "incorrect"
label values earth_oxygen earth_oxygen

gen earth_age3=k130901 
recode earth_age3 (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_age3 1 "correct" 0 "incorrect"
label values earth_age3 earth_age3

gen earth_tides=k073101 
recode earth_tides (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_tides 1 "correct" 0 "incorrect"
label values earth_tides earth_tides

gen earth_core=k101901 
recode earth_core (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_core 1 "correct" 0 "incorrect"
label values earth_core earth_core

gen earth_changes=k101801 
recode earth_changes (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_changes 1 "correct" 0 "incorrect"
label values earth_changes earth_changes

gen earth_temperature=k101701 
recode earth_temperature (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_temperature 1 "correct" 0 "incorrect"
label values earth_temperature earth_temperature

gen earth_gases=k047601 
recode earth_gases (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define earth_gases 1 "correct" 0 "incorrect"
label values earth_gases earth_gases

gen climate_temperate=k046901l 
recode climate_temperate (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_temperate 1 "correct" 0 "incorrect"
label values climate_temperate climate_temperate

gen climate_recognition=k048701m 
recode climate_recognition (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_recognition 1 "correct" 0 "incorrect"
label values climate_recognition climate_recognition

gen climate_evaporation=k049806g 
recode climate_evaporation (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_evaporation 1 "correct" 0 "incorrect"
label values climate_evaporation climate_evaporation

gen climate_areas=k046901 
recode climate_areas (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_areas 1 "correct" 0 "incorrect"
label values climate_areas climate_areas

gen climate_classification=k105101 
recode climate_classification (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_classification 1 "correct" 0 "incorrect"
label values climate_classification climate_classification

gen climate_absence=k106001 
recode climate_absence (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_absence 1 "correct" 0 "incorrect"
label values climate_absence climate_absence

gen climate_monoxide=k106201 
recode climate_monoxide (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_monoxide 1 "correct" 0 "incorrect"
label values climate_monoxide climate_monoxide

gen climate_increase=k105001 
recode climate_increase (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_increase 1 "correct" 0 "incorrect"
label values climate_increase climate_increase

gen climate_fluctuation=k104801 
recode climate_fluctuation (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_fluctuation 1 "correct" 0 "incorrect"
label values climate_fluctuation climate_fluctuation

gen climate_concerns=k104901 
recode climate_concerns (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_concerns 1 "correct" 0 "incorrect"
label values climate_concerns climate_concerns

gen climate_nitrogen=k104601 
recode climate_nitrogen (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_nitrogen 1 "correct" 0 "incorrect"
label values climate_nitrogen climate_nitrogen

gen climate_use=k105201 
recode climate_use (0=0) (1=0) (2=1) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_use 1 "correct" 0 "incorrect"
label values climate_use climate_use

gen climate_hydrocarbon=k096301 
recode climate_hydrocarbon (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_hydrocarbon 1 "correct" 0 "incorrect"
label values climate_hydrocarbon climate_hydrocarbon

gen climate_infrared=k157701 
recode climate_infrared (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_infrared 1 "correct" 0 "incorrect"
label values climate_infrared climate_infrared

gen climate_changes=k157801 
recode climate_changes (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_changes 1 "correct" 0 "incorrect"
label values climate_changes climate_changes

gen climate_reduction=k157901 
recode climate_reduction (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_reduction 1 "correct" 0 "incorrect"
label values climate_reduction climate_reduction

gen climate_plant=k135601 
recode climate_plant (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_plant 1 "correct" 0 "incorrect"
label values climate_plant climate_plant

gen climate_volcano=k141901 
recode climate_volcano (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_volcano 1 "correct" 0 "incorrect"
label values climate_volcano climate_volcano

gen climate_chemical=k126601 
recode climate_chemical (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_chemical 1 "correct" 0 "incorrect"
label values climate_chemical climate_chemical

gen climate_compounds=k143401 
recode climate_compounds (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_compounds 1 "correct" 0 "incorrect"
label values climate_compounds climate_compounds

gen climate_weather=k094801 
recode climate_weather (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_weather 1 "correct" 0 "incorrect"
label values climate_weather climate_weather

gen climate_co2=k125803 
recode climate_co2 (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define climate_co2 1 "correct" 0 "incorrect"
label values climate_co2 climate_co2

gen pollution_air=k049401 
recode pollution_air (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define pollution_air 1 "correct" 0 "incorrect"
label values pollution_air pollution_air

gen pollution_water=k049402 
recode pollution_water (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define pollution_water 1 "correct" 0 "incorrect"
label values pollution_water pollution_water

gen pollution_reduction=k049403 
recode pollution_reduction (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define pollution_reduction 1 "correct" 0 "incorrect"
label values pollution_reduction pollution_reduction

gen pollution_plan=k049404 
recode pollution_plan (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define pollution_plan 1 "correct" 0 "incorrect"
label values pollution_plan pollution_plan

gen pollution_emissions=k139101 
recode pollution_emissions (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define pollution_emissions 1 "correct" 0 "incorrect"
label values pollution_emissions climate_emissions

gen universe_change=k072401 
recode universe_change (0=0) (1=1) (2=0) (3=0) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_change 1 "correct" 0 "incorrect"
label values universe_change universe_change

gen universe_bang=k072501 
recode universe_bang (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_bang 1 "correct" 0 "incorrect"
label values universe_bang universe_bang

gen universe_evidence=k141801 
recode universe_evidence (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_evidence 1 "correct" 0 "incorrect"
label values universe_evidence universe_evidence

gen universe_matter=k072301 
recode universe_matter (0=0) (1=0) (2=0) (3=0) (4=1) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_matter 1 "correct" 0 "incorrect"
label values universe_matter universe_matter

gen universe_suit=k060001 
recode universe_suit (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_suit 1 "correct" 0 "incorrect"
label values universe_suit universe_suit

gen universe_moon=k142401 
recode universe_moon (0=0) (1=0) (2=0) (3=1) (4=0) (5=0) (6=0) (7=0) (8=0) (9=0)
label define universe_moon 1 "correct" 0 "incorrect"
label values universe_moon universe_moon

egen evo_correct=rowmean(evolution_1996_1 evolution_1996_2 evolution_2000_tree evolution_2000_selection evolution_2000_plants evolution_2000_relationships evolution_2005_selection evolution_2009_tree evolution_2009_fibers evolution_2009_bacteria evolution_2009_genetics evolution_2009_selection)
label variable evo_correct "Evolution Knowledge"

egen v2_evo_correct=rowmean(v2_evolution_1996_1 v2_evolution_1996_2 v2_evolution_2000_tree v2_evolution_2000_selection v2_evolution_2000_plants v2_evolution_2000_relationships v2_evolution_2005_selection v2_evolution_2009_tree v2_evolution_2009_fibers v2_evolution_2009_bacteria v2_evolution_2009_genetics v2_evolution_2009_selection)
label variable v2_evo_correct "Evolution Knowledge"

egen matterandmass_correct=rowmean(matter_acceleration matter_mass matter_cycles matter_phases matter_conservation mass_pendulum mass_force mass_volume mass_gravity universe_matter)
label variable matterandmass_correct "Matter and Mass"

egen energy_correct=rowmean(energy_fan energy_nuclear energy_source energy_release energy_conversion energy_transformation energy_plant energy_transfer energy_forces energy_storage energy_peanut energy_peanut2 energy_kinetic energy_trampoline energy_potential energy_water energy_change energy_levels energy_decrease energy_molecules)
label variable energy_correct "Energy"

egen motion_correct=rowmean(motion_graph motion_ice motion_object motion_molecule motion_solid motion_time motion_car motion_sled motion_second motion_interval)
label variable motion_correct "Motion"

egen reproduction_correct=rowmean(reproduction_diff reproduction_plants reproduction_general reproduction_asexual reproduction_definition reproduction_effect reproduction_hemoglobin reproduction_cell reproduction_enzymes reproduction_engineering reproduction_regulation reproduction_disorders reproduction_mutations reproduction_relatedness reproduction_parents reproduction_offspring reproduction_chromosomes reproduction_data reproduction_genetics reproduction_mutations2 reproduction_sexual reproduction_grain reproduction_advantage evolution_2009_genetics)
label variable reproduction_correct "Reproduction"

egen tectonics_correct=rowmean(tectonics_earthquakes2 tectonics_composition tectonics_layers tectonics_comparison tectonics_plate tectonics_volcano tectonics_movement tectonics_mountains tectonics_properties tectonics_circulation tectonics_eruptions tectonics_earthquakes tectonics_sea tectonics_land tectonics_model tectonics_theory)
label variable tectonics_correct "Tectonics"

egen earth_correct=rowmean(earth_atmosphere earth_gases earth_temperature earth_changes earth_core earth_tides earth_age3 earth_oxygen earth_heat2 earth_age2 earth_heat earth_age earth_surface)
label variable earth_correct "Earth"

egen climate_correct=rowmean(climate_classification climate_absence climate_monoxide climate_increase climate_fluctuation climate_concerns climate_nitrogen climate_use climate_hydrocarbon climate_weather climate_areas climate_infrared climate_changes climate_reduction climate_plant climate_volcano climate_chemical climate_compounds climate_co2 pollution_emissions)
label variable climate_correct "Climate Change"

egen pollution_correct=rowmean(pollution_air pollution_water pollution_reduction pollution_plan pollution_emissions)
label variable pollution_correct "Pollution"

egen universe_correct=rowmean(universe_matter universe_evidence universe_change universe_bang universe_suit universe_moon)
label variable universe_correct "Universe"

egen placebo_share_correct_all=rowmean(matter_acceleration matter_mass matter_cycles matter_phases matter_conservation mass_pendulum mass_force mass_volume mass_gravity universe_matter energy_fan energy_nuclear energy_source energy_release energy_conversion energy_transformation energy_plant energy_transfer energy_forces energy_storage energy_peanut energy_peanut2 energy_kinetic energy_trampoline energy_potential energy_water energy_change energy_levels energy_decrease energy_molecules motion_graph motion_ice motion_object motion_molecule motion_solid motion_time motion_car motion_sled motion_second motion_interval reproduction_diff reproduction_plants reproduction_general reproduction_asexual reproduction_definition reproduction_effect reproduction_hemoglobin reproduction_cell reproduction_enzymes reproduction_engineering reproduction_regulation reproduction_disorders reproduction_mutations reproduction_relatedness reproduction_parents reproduction_offspring reproduction_chromosomes reproduction_data reproduction_genetics reproduction_mutations2 reproduction_sexual reproduction_grain reproduction_advantage evolution_2009_genetics  tectonics_earthquakes2 tectonics_composition tectonics_layers tectonics_comparison tectonics_plate tectonics_volcano tectonics_movement tectonics_mountains tectonics_properties tectonics_circulation tectonics_eruptions tectonics_earthquakes tectonics_sea tectonics_land tectonics_model tectonics_theory earth_atmosphere earth_gases earth_temperature earth_changes earth_core earth_tides earth_age3 earth_oxygen earth_heat2 earth_age2 earth_heat earth_age earth_surface climate_classification climate_absence climate_monoxide climate_increase climate_fluctuation climate_concerns climate_nitrogen climate_use climate_hydrocarbon climate_weather climate_areas climate_infrared climate_changes climate_reduction climate_plant climate_volcano climate_chemical climate_compounds climate_co2 pollution_emissions pollution_air pollution_water pollution_reduction pollution_plan pollution_emissions universe_matter universe_evidence universe_change universe_bang universe_suit universe_moon)
label variable placebo_share_correct_all "Non-Evolution Scientific Topics: Average"

gen biology1=k816806 
replace biology1=1 if k813a06==1
replace biology1=2 if k813b06==1
replace biology1=3 if k813c06==1
replace biology1=4 if k813d06==1
replace biology1=5 if k813e06==1
replace biology1=6 if k813f06==1
gen biology1_ever = biology1
recode biology1_ever (0=.) (1=0) (2=1) (3=1) (4=1) (5=1) (6=1) (8=.)
replace biology1_ever=1 if k812503b==1 | k812503b==2 | k812503b==3
replace biology1_ever=0 if k812503b==4

gen biology2=k816807 
replace biology2=1 if k813a07==1
replace biology2=2 if k813b07==1
replace biology2=3 if k813c07==1
replace biology2=4 if k813d07==1
replace biology2=5 if k813e07==1
replace biology2=6 if k813f07==1
gen biology2_ever = biology2
recode biology2_ever (0=.) (1=0) (2=1) (3=1) (4=1) (5=1) (6=1) (8=.)
replace biology2_ever=1 if k812503b==1 
replace biology2_ever=0 if k812503b==2 | k812503b==3 | k812503b==4

gen biologyap_ever = k8138a1 
recode biologyap_ever (8=0)

***prepare treatment

gen highschoolentryyear=year-3
gen highschoolentryyearcs = highschoolentryyear
recode highschoolentryyearcs (1997=1998) (1993=1994)

gen evolution_score=.
replace evolution_score=9 if state==1 & highschoolentryyear<2005
replace evolution_score=21 if state==1 & highschoolentryyear>=2005
replace evolution_score=48 if state==2 & highschoolentryyear<2006
replace evolution_score=59 if state==2 & highschoolentryyear>=2006
replace evolution_score=82 if state==4 & highschoolentryyear<2005
replace evolution_score=82 if state==4 & highschoolentryyear>=2005
replace evolution_score=55 if state==5 & highschoolentryyear<2005
replace evolution_score=66 if state==5 & highschoolentryyear>=2005
replace evolution_score=100 if state==6
replace evolution_score=86 if state==8 & highschoolentryyear<2009
replace evolution_score=82 if state==8 & highschoolentryyear>=2009
replace evolution_score=100 if state==9 & highschoolentryyear<2004
replace evolution_score=59 if state==9 & highschoolentryyear>=2004
replace evolution_score=91 if state==10 & highschoolentryyear<2006
replace evolution_score=80 if state==10 & highschoolentryyear>=2006
replace evolution_score=80 if state==11 & highschoolentryyear<2006
replace evolution_score=96 if state==11 & highschoolentryyear>=2006
replace evolution_score=16 if state==12 & highschoolentryyear<2008
replace evolution_score=91 if state==12 & highschoolentryyear>=2008
replace evolution_score=7 if state==13 & highschoolentryyear<2004
replace evolution_score=66 if state==13 & highschoolentryyear>=2004
replace evolution_score=91 if state==15 & highschoolentryyear<2005
replace evolution_score=75 if state==15 & highschoolentryyear>=2005
replace evolution_score=82 if state==16 & highschoolentryyear<2007
replace evolution_score=82 if state==16 & highschoolentryyear>=2007
replace evolution_score=45 if state==17 & highschoolentryyear<2004
replace evolution_score=82 if state==17 & highschoolentryyear>=2004
replace evolution_score=100 if state==18 & highschoolentryyear<2006
replace evolution_score=96 if state==18 & highschoolentryyear>=2006
replace evolution_score=77 if state==19 & highschoolentryyear>=2007
replace evolution_score=0 if state==20 & highschoolentryyear<2007
replace evolution_score=96 if state==20 & highschoolentryyear>=2007
replace evolution_score=55 if state==21 & highschoolentryyear<2006
replace evolution_score=55 if state==21 & highschoolentryyear>=2006
replace evolution_score=64 if state==22 & highschoolentryyear<2005
replace evolution_score=27 if state==22 & highschoolentryyear>=2005
replace evolution_score=30 if state==23 & highschoolentryyear<2007
replace evolution_score=68 if state==23 & highschoolentryyear>=2007
replace evolution_score=77 if state==24 & highschoolentryyear<2002
replace evolution_score=73 if state==24 & highschoolentryyear>=2002
replace evolution_score=82 if state==25 & highschoolentryyear<2006
replace evolution_score=84 if state==25 & highschoolentryyear>=2006
replace evolution_score=84 if state==26 & highschoolentryyear<2000
replace evolution_score=80 if state==26 & highschoolentryyear>=2000
replace evolution_score=86 if state==27 & highschoolentryyear<2009
replace evolution_score=89 if state==27 & highschoolentryyear>=2009
replace evolution_score=5 if state==28 & highschoolentryyear<2008
replace evolution_score=87 if state==28 & highschoolentryyear>=2008
replace evolution_score=82 if state==29 & highschoolentryyear<2008
replace evolution_score=78 if state==29 & highschoolentryyear>=2008
replace evolution_score=82 if state==30 & highschoolentryyear<2006
replace evolution_score=75 if state==30 & highschoolentryyear>=2006
replace evolution_score=66 if state==31 
replace evolution_score=70 if state==32 & highschoolentryyear<2004
replace evolution_score=77 if state==32 & highschoolentryyear>=2004
replace evolution_score=23 if state==33 & highschoolentryyear<2006
replace evolution_score=91 if state==33 & highschoolentryyear>=2006
replace evolution_score=100 if state==34 & highschoolentryyear<2002
replace evolution_score=100 if state==34 & highschoolentryyear>=2002
replace evolution_score=73 if state==35 & highschoolentryyear<2003
replace evolution_score=91 if state==35 & highschoolentryyear>=2003
replace evolution_score=68 if state==36
replace evolution_score=100 if state==37 & highschoolentryyear<2004
replace evolution_score=82 if state==37 & highschoolentryyear>=2004
replace evolution_score=9 if state==38 & highschoolentryyear<2006
replace evolution_score=64 if state==38 & highschoolentryyear>=2006
replace evolution_score=30 if state==39 & highschoolentryyear<2006
replace evolution_score=86 if state==39 & highschoolentryyear>=2006
replace evolution_score=25 if state==40 & highschoolentryyear<2005
replace evolution_score=25 if state==40 & highschoolentryyear>=2005
replace evolution_score=82 if state==41 & highschoolentryyear<2009
replace evolution_score=82 if state==41 & highschoolentryyear>=2009
replace evolution_score=91 if state==42 & highschoolentryyear<2002
replace evolution_score=96 if state==42 & highschoolentryyear>=2002
replace evolution_score=100 if state==44 & highschoolentryyear<2006
replace evolution_score=82 if state==44 & highschoolentryyear>=2006
replace evolution_score=95 if state==45 & highschoolentryyear<2005
replace evolution_score=91 if state==45 & highschoolentryyear>=2005
replace evolution_score=82 if state==46 & highschoolentryyear<2005
replace evolution_score=77 if state==46 & highschoolentryyear>=2005
replace evolution_score=2 if state==47 & highschoolentryyear<2007
replace evolution_score=55 if state==47 & highschoolentryyear>=2007
replace evolution_score=64 if state==48 & highschoolentryyear<2009
replace evolution_score=46 if state==48 & highschoolentryyear>=2009
replace evolution_score=82 if state==49 & highschoolentryyear<2003
replace evolution_score=82 if state==49 & highschoolentryyear>=2003
replace evolution_score=86 if state==50 & highschoolentryyear<2000
replace evolution_score=86 if state==50 & highschoolentryyear>=2000
replace evolution_score=50 if state==51 & highschoolentryyear<2003
replace evolution_score=68 if state==51 & highschoolentryyear>=2003
replace evolution_score=86 if state==53 & highschoolentryyear<2005
replace evolution_score=86 if state==53 & highschoolentryyear>=2005
replace evolution_score=2 if state==54 & highschoolentryyear<2008
replace evolution_score=46 if state==54 & highschoolentryyear>=2008
replace evolution_score=55 if state==55
replace evolution_score=36 if state==56 & highschoolentryyear<2003
replace evolution_score=61 if state==56 & highschoolentryyear>=2003
gen evo_score = evolution_score/100
label variable evo_score "Evolution Score"

gen evolution_score_dosage=.
replace evolution_score_dosage= 9 if state==1 & highschoolentryyear<2002
replace evolution_score_dosage= 12 if state==1 & highschoolentryyear==2002
replace evolution_score_dosage= 15 if state==1 & highschoolentryyear==2003
replace evolution_score_dosage= 18 if state==1 & highschoolentryyear==2004
replace evolution_score_dosage= 21 if state==1 & highschoolentryyear>=2005
replace evolution_score_dosage= 48 if state==2 & highschoolentryyear<2003
replace evolution_score_dosage= 50.75 if state==2 & highschoolentryyear==2003
replace evolution_score_dosage= 53.5 if state==2 & highschoolentryyear==2004
replace evolution_score_dosage= 56.25 if state==2 & highschoolentryyear==2005
replace evolution_score_dosage= 59 if state==2 & highschoolentryyear>=2006
replace evolution_score_dosage= 82 if state==4 & highschoolentryyear<2005
replace evolution_score_dosage= 82 if state==4 & highschoolentryyear>=2005
replace evolution_score_dosage= 55 if state==5 & highschoolentryyear<2002
replace evolution_score_dosage= 57.75 if state==5 & highschoolentryyear==2002
replace evolution_score_dosage= 60.5 if state==5 & highschoolentryyear==2003
replace evolution_score_dosage= 63.25 if state==5 & highschoolentryyear==2004
replace evolution_score_dosage= 66 if state==5 & highschoolentryyear>=2005
replace evolution_score_dosage= 100 if state==6
replace evolution_score_dosage= 86 if state==8 & highschoolentryyear<2006
replace evolution_score_dosage= 85 if state==8 & highschoolentryyear==2006
replace evolution_score_dosage= 84 if state==8 & highschoolentryyear==2007
replace evolution_score_dosage= 83 if state==8 & highschoolentryyear==2008
replace evolution_score_dosage= 82 if state==8 & highschoolentryyear>=2009
replace evolution_score_dosage= 100 if state==9 & highschoolentryyear<2001
replace evolution_score_dosage= 89.75 if state==9 & highschoolentryyear==2001
replace evolution_score_dosage= 79.5 if state==9 & highschoolentryyear==2002
replace evolution_score_dosage= 69.25 if state==9 & highschoolentryyear==2003
replace evolution_score_dosage= 59 if state==9 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if state==10 & highschoolentryyear<2003
replace evolution_score_dosage= 88.25 if state==10 & highschoolentryyear==2003
replace evolution_score_dosage= 85.5 if state==10 & highschoolentryyear==2004
replace evolution_score_dosage= 82.75 if state==10 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if state==10 & highschoolentryyear>=2006
replace evolution_score_dosage= 80 if state==11 & highschoolentryyear<2003
replace evolution_score_dosage= 84 if state==11 & highschoolentryyear==2003
replace evolution_score_dosage= 88 if state==11 & highschoolentryyear==2004
replace evolution_score_dosage= 92 if state==11 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if state==11 & highschoolentryyear>=2006
replace evolution_score_dosage= 16 if state==12 & highschoolentryyear<2005
replace evolution_score_dosage= 34.75 if state==12 & highschoolentryyear==2005
replace evolution_score_dosage= 53.5 if state==12 & highschoolentryyear==2006
replace evolution_score_dosage= 72.25 if state==12 & highschoolentryyear==2007
replace evolution_score_dosage= 91 if state==12 & highschoolentryyear>=2008
replace evolution_score_dosage= 7 if state==13 & highschoolentryyear<2001
replace evolution_score_dosage= 21.75 if state==13 & highschoolentryyear==2001
replace evolution_score_dosage= 36.5 if state==13 & highschoolentryyear==2002
replace evolution_score_dosage= 51.25 if state==13 & highschoolentryyear==2003
replace evolution_score_dosage= 66 if state==13 & highschoolentryyear>=2004
replace evolution_score_dosage= 91 if state==15 & highschoolentryyear<2002
replace evolution_score_dosage= 87 if state==15 & highschoolentryyear==2002
replace evolution_score_dosage= 83 if state==15 & highschoolentryyear==2003
replace evolution_score_dosage= 79 if state==15 & highschoolentryyear==2004
replace evolution_score_dosage= 75 if state==15 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state==16 & highschoolentryyear<2007
replace evolution_score_dosage= 82 if state==16 & highschoolentryyear>=2007
replace evolution_score_dosage= 45 if state==17 & highschoolentryyear<2001
replace evolution_score_dosage= 54.25 if state==17 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if state==17 & highschoolentryyear==2002
replace evolution_score_dosage= 72.25 if state==17 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if state==17 & highschoolentryyear>=2004
replace evolution_score_dosage= 100 if state==18 & highschoolentryyear<2003
replace evolution_score_dosage= 99 if state==18 & highschoolentryyear==2003
replace evolution_score_dosage= 98 if state==18 & highschoolentryyear==2004
replace evolution_score_dosage= 97 if state==18 & highschoolentryyear==2005
replace evolution_score_dosage= 96 if state==18 & highschoolentryyear>=2006
replace evolution_score_dosage= 77 if state==19 & highschoolentryyear>=2007
replace evolution_score_dosage= 0 if state==20 & highschoolentryyear<2004
replace evolution_score_dosage= 24 if state==20 & highschoolentryyear==2004
replace evolution_score_dosage= 48 if state==20 & highschoolentryyear==2005
replace evolution_score_dosage= 72 if state==20 & highschoolentryyear==2006
replace evolution_score_dosage= 96 if state==20 & highschoolentryyear>=2007
replace evolution_score_dosage= 55 if state==21 & highschoolentryyear<2006
replace evolution_score_dosage= 55 if state==21 & highschoolentryyear>=2006
replace evolution_score_dosage= 64 if state==22 & highschoolentryyear<2002
replace evolution_score_dosage= 54.75 if state==22 & highschoolentryyear==2002
replace evolution_score_dosage= 45.5 if state==22 & highschoolentryyear==2003
replace evolution_score_dosage= 36.25 if state==22 & highschoolentryyear==2004
replace evolution_score_dosage= 27 if state==22 & highschoolentryyear>=2005
replace evolution_score_dosage= 30 if state==23 & highschoolentryyear<2004
replace evolution_score_dosage= 39.5 if state==23 & highschoolentryyear==2004
replace evolution_score_dosage= 49 if state==23 & highschoolentryyear==2005
replace evolution_score_dosage= 58.5 if state==23 & highschoolentryyear==2006
replace evolution_score_dosage= 68 if state==23 & highschoolentryyear>=2007
replace evolution_score_dosage= 77 if state==24 & highschoolentryyear<1999
replace evolution_score_dosage= 76 if state==24 & highschoolentryyear==1999
replace evolution_score_dosage= 75 if state==24 & highschoolentryyear==2000
replace evolution_score_dosage= 74 if state==24 & highschoolentryyear==2001
replace evolution_score_dosage= 73 if state==24 & highschoolentryyear>=2002
replace evolution_score_dosage= 82 if state==25 & highschoolentryyear<2003
replace evolution_score_dosage= 82.5 if state==25 & highschoolentryyear==2003
replace evolution_score_dosage= 83 if state==25 & highschoolentryyear==2004
replace evolution_score_dosage= 83.5 if state==25 & highschoolentryyear==2005
replace evolution_score_dosage= 84 if state==25 & highschoolentryyear>=2006
replace evolution_score_dosage= 84 if state==26 & highschoolentryyear<1997
replace evolution_score_dosage= 83 if state==26 & highschoolentryyear==1997
replace evolution_score_dosage= 82 if state==26 & highschoolentryyear==1998
replace evolution_score_dosage= 81 if state==26 & highschoolentryyear==1999
replace evolution_score_dosage= 80 if state==26 & highschoolentryyear>=2000
replace evolution_score_dosage= 86 if state==27 & highschoolentryyear<2006
replace evolution_score_dosage= 86.75 if state==27 & highschoolentryyear==2006
replace evolution_score_dosage= 87.5 if state==27 & highschoolentryyear==2007
replace evolution_score_dosage= 88.25 if state==27 & highschoolentryyear==2008
replace evolution_score_dosage= 89 if state==27 & highschoolentryyear>=2009
replace evolution_score_dosage= 5 if state==28 & highschoolentryyear<2005
replace evolution_score_dosage= 25.5 if state==28 & highschoolentryyear==2005
replace evolution_score_dosage= 45.5 if state==28 & highschoolentryyear==2006
replace evolution_score_dosage= 65.75 if state==28 & highschoolentryyear==2007
replace evolution_score_dosage= 86 if state==28 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if state==29 & highschoolentryyear<2005
replace evolution_score_dosage= 81 if state==29 & highschoolentryyear==2005
replace evolution_score_dosage= 80 if state==29 & highschoolentryyear==2006
replace evolution_score_dosage= 79 if state==29 & highschoolentryyear==2007
replace evolution_score_dosage= 78 if state==29 & highschoolentryyear>=2008
replace evolution_score_dosage= 82 if state==30 & highschoolentryyear<2003
replace evolution_score_dosage= 80.25 if state==30 & highschoolentryyear==2003
replace evolution_score_dosage= 78.5 if state==30 & highschoolentryyear==2004
replace evolution_score_dosage= 76.75 if state==30 & highschoolentryyear==2005
replace evolution_score_dosage= 75 if state==30 & highschoolentryyear>=2006
replace evolution_score_dosage= 66 if state==31 
replace evolution_score_dosage= 70 if state==32 & highschoolentryyear<2001
replace evolution_score_dosage= 71.75 if state==32 & highschoolentryyear==2001
replace evolution_score_dosage= 73.5 if state==32 & highschoolentryyear==2002
replace evolution_score_dosage= 75.25 if state==32 & highschoolentryyear==2003
replace evolution_score_dosage= 77 if state==32 & highschoolentryyear>=2004
replace evolution_score_dosage= 23 if state==33 & highschoolentryyear<2003
replace evolution_score_dosage= 40 if state==33 & highschoolentryyear==2003
replace evolution_score_dosage= 57 if state==33 & highschoolentryyear==2004
replace evolution_score_dosage= 74 if state==33 & highschoolentryyear==2005
replace evolution_score_dosage= 91 if state==33 & highschoolentryyear>=2006
replace evolution_score_dosage= 100 if state==34 & highschoolentryyear<2002
replace evolution_score_dosage= 100 if state==34 & highschoolentryyear>=2002
replace evolution_score_dosage= 73 if state==35 & highschoolentryyear<2000
replace evolution_score_dosage= 77.5 if state==35 & highschoolentryyear==2000
replace evolution_score_dosage= 82 if state==35 & highschoolentryyear==2001
replace evolution_score_dosage= 86.5 if state==35 & highschoolentryyear==2002
replace evolution_score_dosage= 91 if state==35 & highschoolentryyear>=2003
replace evolution_score_dosage= 68 if state==36 
replace evolution_score_dosage= 100 if state==37 & highschoolentryyear<2001
replace evolution_score_dosage= 95.5 if state==37 & highschoolentryyear==2001
replace evolution_score_dosage= 91 if state==37 & highschoolentryyear==2002
replace evolution_score_dosage= 86.5 if state==37 & highschoolentryyear==2003
replace evolution_score_dosage= 82 if state==37 & highschoolentryyear>=2004
replace evolution_score_dosage= 9 if state==38 & highschoolentryyear<2003
replace evolution_score_dosage= 22.75 if state==38 & highschoolentryyear==2003
replace evolution_score_dosage= 36.5 if state==38 & highschoolentryyear==2004
replace evolution_score_dosage= 50.25 if state==38 & highschoolentryyear==2005
replace evolution_score_dosage= 64 if state==38 & highschoolentryyear>=2006
replace evolution_score_dosage= 30 if state==39 & highschoolentryyear<2003
replace evolution_score_dosage= 44 if state==39 & highschoolentryyear==2003
replace evolution_score_dosage= 58 if state==39 & highschoolentryyear==2004
replace evolution_score_dosage= 72 if state==39 & highschoolentryyear==2005
replace evolution_score_dosage= 86 if state==39 & highschoolentryyear>=2006
replace evolution_score_dosage= 25 if state==40 & highschoolentryyear<2005
replace evolution_score_dosage= 25 if state==40 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state==41 & highschoolentryyear<2009
replace evolution_score_dosage= 82 if state==41 & highschoolentryyear>=2009
replace evolution_score_dosage= 91 if state==42 & highschoolentryyear<2002
replace evolution_score_dosage= 92.25 if state==42 & highschoolentryyear==2002
replace evolution_score_dosage= 93.5 if state==42 & highschoolentryyear==2002
replace evolution_score_dosage= 94.75 if state==42 & highschoolentryyear==2002
replace evolution_score_dosage= 96 if state==42 & highschoolentryyear>=2002
replace evolution_score_dosage= 100 if state==44 & highschoolentryyear<2003
replace evolution_score_dosage= 95.5 if state==44 & highschoolentryyear==2003
replace evolution_score_dosage= 91 if state==44 & highschoolentryyear==2004
replace evolution_score_dosage= 86.5 if state==44 & highschoolentryyear==2005
replace evolution_score_dosage= 82 if state==44 & highschoolentryyear>=2006
replace evolution_score_dosage= 95 if state==45 & highschoolentryyear<2002
replace evolution_score_dosage= 94 if state==45 & highschoolentryyear==2002
replace evolution_score_dosage= 93 if state==45 & highschoolentryyear==2003
replace evolution_score_dosage= 92 if state==45 & highschoolentryyear==2004
replace evolution_score_dosage= 91 if state==45 & highschoolentryyear>=2005
replace evolution_score_dosage= 82 if state==46 & highschoolentryyear<2002
replace evolution_score_dosage= 80.75 if state==46 & highschoolentryyear==2002
replace evolution_score_dosage= 79.5 if state==46 & highschoolentryyear==2003
replace evolution_score_dosage= 78.25 if state==46 & highschoolentryyear==2004
replace evolution_score_dosage= 77 if state==46 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if state==47 & highschoolentryyear<2004
replace evolution_score_dosage= 15.25 if state==47 & highschoolentryyear==2004
replace evolution_score_dosage= 28.5 if state==47 & highschoolentryyear==2005
replace evolution_score_dosage= 41.75 if state==47 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if state==47 & highschoolentryyear>=2007
replace evolution_score_dosage= 64 if state==48 & highschoolentryyear<2006
replace evolution_score_dosage= 59.5 if state==48 & highschoolentryyear==2006
replace evolution_score_dosage= 55 if state==48 & highschoolentryyear==2007
replace evolution_score_dosage= 50.5 if state==48 & highschoolentryyear==2008
replace evolution_score_dosage= 46 if state==48 & highschoolentryyear>=2009
replace evolution_score_dosage= 82 if state==49 & highschoolentryyear<2003
replace evolution_score_dosage= 82 if state==49 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if state==50 & highschoolentryyear<2000
replace evolution_score_dosage= 86 if state==50 & highschoolentryyear>=2000
replace evolution_score_dosage= 50 if state==51 & highschoolentryyear<2000
replace evolution_score_dosage= 54.5 if state==51 & highschoolentryyear==2000
replace evolution_score_dosage= 59 if state==51 & highschoolentryyear==2001
replace evolution_score_dosage= 63.5 if state==51 & highschoolentryyear==2002
replace evolution_score_dosage= 68 if state==51 & highschoolentryyear>=2003
replace evolution_score_dosage= 86 if state==53 & highschoolentryyear<2005
replace evolution_score_dosage= 86 if state==53 & highschoolentryyear>=2005
replace evolution_score_dosage= 2 if state==54 & highschoolentryyear<2005
replace evolution_score_dosage= 13 if state==54 & highschoolentryyear==2005
replace evolution_score_dosage= 24 if state==54 & highschoolentryyear==2006
replace evolution_score_dosage= 35 if state==54 & highschoolentryyear==2007
replace evolution_score_dosage= 46 if state==54 & highschoolentryyear>=2008
replace evolution_score_dosage= 2 if state==55 
replace evolution_score_dosage= 36 if state==56 & highschoolentryyear<2000
replace evolution_score_dosage= 42.25 if state==56 & highschoolentryyear==2000
replace evolution_score_dosage= 48.5 if state==56 & highschoolentryyear==2001
replace evolution_score_dosage= 54.75 if state==56 & highschoolentryyear==2002
replace evolution_score_dosage= 61 if state==56 & highschoolentryyear>=2003
gen evo_score_dosage=evolution_score_dosage/100
label variable evo_score_dosage "Evolution Score"

foreach i of num 1/9 { 
gen evo_score_`i'=0
replace evo_score_`i'=1 if evo_score>0.`i'
replace evo_score_`i'=. if evo_score==.
label variable evo_score_`i' "Evolution Score $>$ 0.`i'0"
}

gen more_evolution=0 
replace more_evolution=1 if state==1 | state==2 |  state==5 |  state==11 | state==12 |  state==13 |  state==17 |  state==20 |  state==23 |  state==25 |  state==27 |  state==28 |  state==32 |  state==33 |  state==35 |  state==38 |  state==39 |  state==42 |  state==47 |  state==51 |  state==54 |  state==56

gen less_evolution=0 
replace less_evolution=1 if state==8 |  state==9 |  state==10 |  state==15 | state==18 | state==22 |  state==24 |  state==26 |  state==29 |  state==30 | state==37 |  state==44 |  state==45 |  state==46 |  state==48

gen equal_evolution=0 
replace equal_evolution=1 if state==4 | state==6 |   state==16 |  state==19 |  state==21 |  state==31 |  state==34 |  state==36 |  state==40 |  state==41 |  state==49 |  state==50 |  state==53 |  state==55

gen first_treat =.
replace first_treat=2005 if state==1
replace first_treat=2006 if state==2
replace first_treat=2005 if state==4
replace first_treat=2005 if state==5
replace first_treat=2009 if state==8
replace first_treat=2004 if state==9
replace first_treat=2006 if state==10
replace first_treat=2006 if state==11
replace first_treat=2008 if state==12
replace first_treat=2004 if state==13
replace first_treat=2005 if state==15
replace first_treat=2007 if state==16
replace first_treat=2004 if state==17
replace first_treat=2006 if state==18
replace first_treat=2007 if state==20
replace first_treat=2006 if state==21
replace first_treat=2005 if state==22
replace first_treat=2007 if state==23
replace first_treat=2002 if state==24
replace first_treat=2006 if state==25
replace first_treat=2000 if state==26
replace first_treat=2009 if state==27
replace first_treat=2008 if state==28
replace first_treat=2008 if state==29
replace first_treat=2006 if state==30
replace first_treat=2004 if state==32
replace first_treat=2006 if state==33
replace first_treat=2002 if state==34
replace first_treat=2003 if state==35
replace first_treat=2004 if state==37
replace first_treat=2006 if state==38
replace first_treat=2006 if state==39
replace first_treat=2005 if state==40
replace first_treat=2009 if state==41
replace first_treat=2002 if state==42
replace first_treat=2006 if state==44
replace first_treat=2005 if state==45
replace first_treat=2005 if state==46
replace first_treat=2007 if state==47
replace first_treat=2009 if state==48
replace first_treat=2003 if state==49
replace first_treat=2000 if state==50
replace first_treat=2003 if state==51
replace first_treat=2005 if state==53
replace first_treat=2008 if state==54
replace first_treat=2003 if state==56
replace first_treat=0 if first_treat==.
gene id=_n

generate trend=0
replace trend= highschoolentryyear - 2005 if state==1
replace trend= highschoolentryyear - 2006 if state==2
replace trend= highschoolentryyear - 2005 if state==5
replace trend= highschoolentryyear - 2009 if state==8
replace trend= highschoolentryyear - 2004 if state==9
replace trend= highschoolentryyear - 2006 if state==10
replace trend= highschoolentryyear - 2006 if state==11
replace trend= highschoolentryyear - 2008 if state==12
replace trend= highschoolentryyear - 2004 if state==13
replace trend= highschoolentryyear - 2005 if state==15
replace trend= highschoolentryyear - 2004 if state==17
replace trend= highschoolentryyear - 2006 if state==18
replace trend= highschoolentryyear - 2007 if state==19
replace trend= highschoolentryyear - 2007 if state==20
replace trend= highschoolentryyear - 2005 if state==22
replace trend= highschoolentryyear - 2007 if state==23
replace trend= highschoolentryyear - 2002 if state==24
replace trend= highschoolentryyear - 2006 if state==25
replace trend= highschoolentryyear - 2000 if state==26
replace trend= highschoolentryyear - 2009 if state==27
replace trend= highschoolentryyear - 2008 if state==28
replace trend= highschoolentryyear - 2008 if state==29
replace trend= highschoolentryyear - 2006 if state==30
replace trend= highschoolentryyear - 2004 if state==32
replace trend= highschoolentryyear - 2006 if state==33
replace trend= highschoolentryyear - 2003 if state==35
replace trend= highschoolentryyear - 2004 if state==37
replace trend= highschoolentryyear - 2006 if state==38
replace trend= highschoolentryyear - 2006 if state==39
replace trend= highschoolentryyear - 2002 if state==42
replace trend= highschoolentryyear - 2006 if state==44
replace trend= highschoolentryyear - 2005 if state==45
replace trend= highschoolentryyear - 2005 if state==46
replace trend= highschoolentryyear - 2007 if state==47
replace trend= highschoolentryyear - 2009 if state==48
replace trend= highschoolentryyear - 2003 if state==51
replace trend= highschoolentryyear - 2008 if state==54
replace trend= highschoolentryyear - 2003 if state==56

gen evo_correct_conv = evo_correct
replace evo_correct_conv = evo_correct_conv*(-1) if less_evolution==1


gen private=.
replace private=1 if schtype>1
replace private=0 if schtype==1

gen closestate10=0
replace closestate10=1 if state==4 | state==5 | state==10 | state==12 | state==13 | state==15 | state==16 | state==17 | state==18 | state==19 | state==23 | state==25 | state==29 | state==30 | state==33 | state==37 | state==40 | state==41 | state==44 | state==51 | state==56
replace closestate10=. if state==.

gen onereform=0
replace onereform=1 if state==5 | state==9 | state==10 | state==11 | state==12 | state==13 | state==15 | state==17 | state==23 | state==26 | state==30 | state==32 | state==33 | state==35 | state==37 | state==42 | state==44 | state==46 | state==48 | state==51 | state==56
replace onereform=. if state==.

gen largestate=0
replace largestate=1 if state==6 | state==48 | state==12 | state==36 | state==42 | state==17 | state==39 | state==13 | state==37 | state==26 | state==34 | state==51 | state==53 | state==4 | state==25 | state==47 | state==18 | state==24 | state==29 | state==55
replace largestate=. if state==.

gen textstate=0
replace textstate=1 if state==2 | state==5 | state==6 | state==8 | state==9 | state==10 | state==12| state==13| state==16| state==17| state==25| state==26| state==27| state==29| state==31| state==32| state==34| state==36| state==37 | state==39| state==41| state==44| state==46| state==49| state==50| state==51| state==55
replace textstate=. if state==.

***prepare controls

rename sex female
recode female (2=1) (1=0)
label define female 1 "female" 0 "male"
label values female female
drop if female==.
label variable female "Female"

replace race=srace if year==2005
replace race=sdracem if year==2009
gen race_white=0
replace race_white=1 if race==1
label variable race_white "Race/Ethnicity: White"
gen race_black=0
replace race_black=1 if race==2
label variable race_black "Race/Ethnicity: Black"
gen race_hispanic=0
replace race_hispanic=1 if race==3
label variable race_hispanic "Race/Ethnicity: Hispanic"
gen race_asian=0
replace race_asian=1 if race==4
label variable race_asian "Race/Ethnicity: Asian"
gen race_other=0
replace race_other=1 if race==5 | race==6
label variable race_other "Race/Ethnicity: Other"

gen sublunch=slunch1
recode sublunch (1=1)(2=0)(3=.)
label variable sublunch "Subsidized Lunch"

gen hp_books=b013801
replace hp_books=b008801 if year==2000
replace hp_books=b008801a if year==1996
recode hp_books (0=.) (1=1) (2=1) (3=2) (4=3) (5=4) (8=.)

gen books_athome_few=0
replace books_athome_few=1 if hp_books==1
replace books_athome_few=. if hp_books==.
label variable books_athome_few "Books at Home: 0-10"
gen books_athome_shelf=0
replace books_athome_shelf=1 if hp_books==2
replace books_athome_shelf=. if hp_books==.
label variable books_athome_shelf "Books at Home: 11-25"
gen books_athome_bookcase=0
replace books_athome_bookcase=1 if hp_books==3
replace books_athome_bookcase=. if hp_books==.
label variable books_athome_bookcase "Books at Home: 26-100"
gen bookcase = books_athome_bookcase
label variable bookcase "Books at Home: 26-100"
gen books_athome_many=0
replace books_athome_many=1 if hp_books==4
replace books_athome_many=. if hp_books==.
label variable books_athome_many "Books at Home: >100"

gen pc_athome1= b017101
recode pc_athome1 (0=.) (1=1) (2=0) (8=.)
gen pc_athome2= b009301
recode pc_athome2 (0=.) (1=1) (2=1) (3=1) (4=1) (5=0) (8=.)
gen pc_athome3= b009301a
recode pc_athome3 (0=.) (1=1) (2=1) (3=1) (4=1) (5=0) (8=.)
replace pc_athome1=pc_athome2 if year==2000
replace pc_athome1=pc_athome3 if year==1996
gen pc_athome=pc_athome1
label variable pc_athome "Computer at Home"

label variable sessno "Test Session"
label variable bmonth "Birth Month"

recode byear (82=1982) (81=1981) (80=1980) (79=1979) (78=1978) (77=1977) (76=1976) (75=1975) (74=1974) (73=1973) (72=1972) (71=1971) (70=1970)
drop if byear>=1993
drop if byear<=1972

global controls "female race_black race_hispanic race_asian race_other sublunch books_athome_shelf books_athome_bookcase books_athome_many pc_athome i.sessno i.bmonth"
global controls_pub_priv "female race_black race_hispanic race_asian race_other books_athome_shelf books_athome_bookcase books_athome_many pc_athome i.sessno i.bmonth"
global controls_trend "female race_black race_hispanic race_asian race_other"

gen year_rescaled=byear-1973
tab state, generate(state_dum)

forval i = 1/51 {
gen statelineartrend`i'=year_rescaled*state_dum`i'
gen sq_statelineartrend`i'=year_rescaled*year_rescaled*state_dum`i'
}

global statelineartrend "statelineartrend*"
global sq_statelineartrend "sq_statelineartrend*"

***prepare event studies

gen zero=0

gen pre78=0
replace pre78=1 if trend==-7 | trend<=-8
replace pre78=. if trend==.

gen pre56=0
replace pre56=1 if trend==-5 | trend==-6
replace pre56=. if trend==.

gen pre34=0
replace pre34=1 if trend==-3 | trend==-4
replace pre34=. if trend==.

gen pre12=0
replace pre12=1 if trend==-1 | trend==-2
replace pre12=. if trend==.

gen post01=0
replace post01=1 if trend==0 | trend==1
replace post01=. if trend==.

gen post23=0
replace post23=1 if trend==2| trend==3
replace post23=. if trend==.

gen post45=0
replace post45=1 if trend==4| trend>=5
replace post45=. if trend==.

***merge other datasets

drop _merge
merge m:1 highschoolentryyear state  using "${path}\data\states\governors19912009.dta"
drop _merge
keep if highschoolentryyear==1993 | highschoolentryyear==1997 | highschoolentryyear==2002 | highschoolentryyear==2006

***prepare sample and save data

reg evo_correct evo_score $controls  i.state i.year i.byear if schtype==1, vce(cluster state) baselevels
gen sample_naep=e(sample)

reg evo_correct evo_score $controls_pub_priv  i.state i.year i.byear if schtype>1 | (schtype==1 & sample_naep==1), vce(cluster state) baselevels
gen sample_naep_priv_pub=e(sample)

gen sample_less=0
replace sample_less=1 if schtype==1 & less_evolution==1

gen sample_more=0
replace sample_more=1 if schtype==1 & more_evolution==1

save "${path}\data\naep\naep_ready.dta", replace